﻿using Hospital.IService;
using Hospital.Model.Pay;
using Hospital.Utility.ApiResult;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Hospital.WebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class OrderController : ControllerBase
    {
        private readonly IOrderService _iOrderService;
        public OrderController(IOrderService iOrderService)
        {
            _iOrderService = iOrderService;
        }

        [HttpPost]
        public async Task<ActionResult<ApiResult>> PostOrder([FromBody] Order order)
        {
            try
            {
                bool b = await _iOrderService.CreateAsync(order);
                var result = await _iOrderService.FindAsync(a => a.OutTradeNo == order.OutTradeNo);
                if (b) return ApiResultHelper.Success(result.Id);
                return ApiResultHelper.Error(b);
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
                throw;
            }
        }

        //[HttpGet]
        //public Task<ActionResult<ApiResult>> Get
    }
}
